package com.yiyang.controller;

import com.yiyang.entity.Building;
import com.yiyang.entity.Result;
import com.yiyang.service.BuildingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/building")
@Tag(name = "楼宇接口")
public class BuildingController {

   @Resource
    public BuildingService buildingService;

    @GetMapping("/list")
    @Operation(summary = "楼宇列表", description = "返回条件和分页查询的数据信息")
            @ApiResponse(description = "返回列表数据",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = Result.class)
            )
    })

    public Result<List<Building>> getBuilding(
            @Parameter(name = "currentPage",description = "当前页码",required = false)
            @RequestParam(name = "currentPage",defaultValue = "1",required = false) Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "10",required = false)Integer pageSize,
            @RequestParam(name = "name",defaultValue = "",required = false)String name,
            @RequestParam(name = "height",defaultValue = "",required = false)String height){

        return this.buildingService.getBuilding(currentPage,pageSize,name,height);
    }
    @DeleteMapping("/delete")
    public Result<Void> deleteBuilding(@RequestParam(name = "id",required = false)String id){
        return this.buildingService.deleteBuilding(id);
    }
    @PostMapping("/add")
    public Result<Void> addBuilding(@RequestBody Building building){
        return this.buildingService.addBuilding(building);
    }
    @PutMapping("/update")
    public Result<Void> updateBuilding(@RequestBody Building building){
        return  this.buildingService.updateBuilding(building);
    }
}
